label: Make attr_list_merge() use sane merging rules
authorBenjamin Otte <otte@redhat.com>
Fri, 6 Jan 2012 04:10:50 +0000 (05:10 +0100)
committerBenjamin Otte <otte@redhat.com>
Fri, 6 Jan 2012 04:23:42 +0000 (05:23 +0100)
Instead of "attribute with later start index wins, make sure the
attribute list that is merged from takes precedence. This now gives the
multiple attribute lists we use in the label an order:

1) gtk_label_set_attributes()
  These attributes override everything. It's what the function's there
  for after all.
2) markup of label
  Other user-specified attributes come next.
3) attributes for links
  When we apply custom attributes on parts of the text, we put them
  last. We don't want to mess with what the user does. Also, we change
  color and underline, so we usually have something to show.

gtk/gtklabel.c

index fe34fe4f6c34370b17c8d773206449a6b1bab2f0..9597f565a5025f06c95970131e7d4b6caa324387 100644 (file)
@@ -2034,31 +2034,19 @@ gtk_label_set_use_underline_internal (GtkLabel *label,
     }
 }
 
+static gboolean
+my_pango_attr_list_merge_filter (PangoAttribute *attribute,
+                                 gpointer        list)
+{
+  pango_attr_list_change (list, pango_attribute_copy (attribute));
+  return FALSE;
+}
+
 static void
 my_pango_attr_list_merge (PangoAttrList *into,
                           PangoAttrList *from)
 {
-  PangoAttrIterator *iter;
-  PangoAttribute    *attr;
-  GSList            *iter_attrs, *l;
-
-  iter = pango_attr_list_get_iterator (from);
-
-  if (iter)
-    {
-      do
-        {
-          iter_attrs = pango_attr_iterator_get_attrs (iter);
-          for (l = iter_attrs; l; l = l->next)
-            {
-              attr = l->data;
-              pango_attr_list_insert (into, attr);
-            }
-          g_slist_free (iter_attrs);
-        }
-      while (pango_attr_iterator_next (iter));
-      pango_attr_iterator_destroy (iter);
-    }
+  pango_attr_list_filter (from, my_pango_attr_list_merge_filter, into);
 }
 
 /* Calculates text, attrs and mnemonic_keyval from